package cn.ly817.jay.service.impl;

import cn.ly817.jay.DAO.UserDao;
import cn.ly817.jay.entity.User;
import cn.ly817.jay.exceptions.UserException;
import cn.ly817.jay.exceptions.UserNotFoundException;
import cn.ly817.jay.exceptions.UserWrongPwdException;
import cn.ly817.jay.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * Created by LuoYu on 2016/12/5.
 */
@Service
public class UserServiceImpl implements UserService {
    @Autowired
    private UserDao userDao;
    //TODO exception
    @Override
    public User verification(String userName,String password) throws UserException {
        User user = userDao.getUserByName(userName);
        if (user == null){
            throw new UserNotFoundException("未找到【"+userName+"】用户");
        }else if(!user.getPassword().equals(password)){
            throw new UserWrongPwdException("【"+userName+"】用户密码验证错误");
        }else {
            return user;
        }
    }


    @Override
    public long getUsersLeaderId(long userId) {
        return userDao.getUsersLeaderId(userId);
    }
}
